﻿using System;
using System.Data;
using System.Collections;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using FindIt.DAL;
using MySql.Data.MySqlClient;

namespace FindIt.BLL
{
    public class PrivilegedUser:User
    {
        public enum StatusType {normal, warned, removed};
        private double _credit;
        private DateTime _joinDate;
        private DateTime _lastLogin;
        private StatusType _status;
        private ArrayList _complaints;

        public double Credit
        {
            get { return _credit; }
            set { _credit = value; }
        }

        public DateTime JoinDate
        {
            get { return _joinDate; }
            set { _joinDate = value; }
        }

        public DateTime LastLogin
        {
            get { return _lastLogin; }
            set { _lastLogin = value; }
        }

        public StatusType Status
        {
            get { return _status; }
            set { _status = value; }
        }

        public ArrayList Complaints
        {
            get { return _complaints; }
            set { _complaints = value; }
        }

        public static void ChangeCredit(string username, double difference)
        {
            UserDB db = new UserDB();
            db.ChangeCredit(username, difference);
        }

        public void SubmitComplaint(string complaint)
        {
        }


        public void Warn()
        {
            UserDB db = new UserDB();
            db.WarnPU(this.Username);
        }


        public void Remove()
        {
            UserDB db = new UserDB();
            db.RemovePU(this.Username);
        }

        public static ArrayList GetPUList()
        {
            ArrayList list = new ArrayList();
            return list;
        }

        public static ArrayList GetPendingComplaints()
        {
            ArrayList list = new ArrayList();
            return list;
        }

        public static PrivilegedUser GetPUByUsername(string username)
        {
            UserDB db = new UserDB();
            MySqlDataReader dr = db.GetPUByUsername(username);

            PrivilegedUser pu = new PrivilegedUser();

            while (dr.Read())
            {
                pu.Username = dr["Username"].ToString();
                pu.JoinDate = DateTime.Parse(dr["JoinDate"].ToString());
                pu.LastLogin = DateTime.Parse(dr["LastLogin"].ToString());
                pu.Credit = double.Parse(dr["Credit"].ToString());
                pu.Status = (StatusType) Enum.Parse(typeof(StatusType), dr["Status"].ToString());
            }

            return pu;
        }
    }
}
